package cn.jksoft.businessclient.ui.adapter;

import android.content.Context;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.jksoft.businessclient.R;
import cn.jksoft.businessclient.bean.ProductEntity;
import cn.jksoft.businessclient.bean.ProductInfoEntity;
import cn.jksoft.businessclient.bean.WorkBenchEntity;

/**
 * Created by RogersHuang on 16/4/7.
 */
public class ProductInfoAdapter extends RecyclerView.Adapter<ProductInfoAdapter.ItemViewHolder> {
    private Context context;
    private LayoutInflater inflater;
    private List<ProductEntity> dataList;
    private View.OnClickListener itemClickListener;
    private View.OnClickListener buttonClickListenner;

    public void setItemClickListener(View.OnClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    public void setButtonClickListenner(View.OnClickListener buttonClickListenner) {
        this.buttonClickListenner = buttonClickListenner;
    }

    public ProductInfoAdapter(Context context , List<ProductEntity> list) {
        this.context = context;
        this.dataList = list;
        inflater = LayoutInflater.from(context);
    }

    public void addDataList(List<ProductEntity> list){
        this.dataList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public ItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = inflater.inflate(R.layout.item_product_info, viewGroup, false);
        ItemViewHolder itemViewHolder = new ItemViewHolder(view);
        return itemViewHolder;
    }

    @Override
    public void onBindViewHolder(final ItemViewHolder itemViewHolder, int i) {
        ProductEntity dataBean = dataList.get(i);
        itemViewHolder.tvName.setText(dataBean.getPROD_NAME());
        itemViewHolder.tvCount.setText(dataBean.getSTORAGE_NAME()+":"+dataBean.getENABLED_INVENTORY());
        itemViewHolder.tvPrice.setText("￥"+Double.parseDouble(dataBean.getSALE_PRICE())/100);
        itemViewHolder.itemView.setTag(i);
        itemViewHolder.itemView.setOnClickListener(itemClickListener);
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public static class ItemViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.item_tv_name)
        TextView tvName;
        @Bind(R.id.item_tv_price)
        TextView tvPrice;
        @Bind(R.id.item_tv_count)
        TextView tvCount;
        public ItemViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
